package com.zjuh.qss.biz.dao.ibatis;

import java.util.List;

import com.zjuh.qss.biz.dao.TaobaoCatDAO;
import com.zjuh.qss.biz.dao.query.TaobaoCatQuery;
import com.zjuh.qss.biz.domain.taobao.TaobaoCatDO;

public class TaobaoCatDAOIbatis extends BaseIbatisDAO implements TaobaoCatDAO {

	public long create(TaobaoCatDO taobaoCat) {
		return (Long)this.getSqlMapClientTemplate().insert("TaobaoCatDAO.create", taobaoCat);
	}

	public void delete(long id) {
		this.getSqlMapClientTemplate().update("TaobaoCatDAO.delete", id);
	}

	public void update(TaobaoCatDO taobaoCat) {
		this.getSqlMapClientTemplate().update("TaobaoCatDAO.update", taobaoCat);
	}

	public TaobaoCatDO queryById(long id) {
		return (TaobaoCatDO)this.getSqlMapClientTemplate().queryForObject("TaobaoCatDAO.queryById", id);
	}

	public TaobaoCatDO queryByCid(long cid) {
		return (TaobaoCatDO)this.getSqlMapClientTemplate().queryForObject("TaobaoCatDAO.queryByCid", cid);
	}
	
	@Override
	public TaobaoCatDO getLastTaobaoCatDO() {
		return (TaobaoCatDO)this.getSqlMapClientTemplate().queryForObject("TaobaoCatDAO.getLastTaobaoCatDO");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TaobaoCatDO> queryForPage(TaobaoCatQuery taobaoCatQuery) {
		return (List<TaobaoCatDO>)this.getSqlMapClientTemplate().queryForList("TaobaoCatDAO.queryForPage", taobaoCatQuery);
	}

	@Override
	public void saveOrUpdateByCid(TaobaoCatDO taobaoCatDO) {
		TaobaoCatDO inDb = queryByCid(taobaoCatDO.getCid());
		if (inDb != null) {
			// update
			taobaoCatDO.setId(inDb.getId());
			taobaoCatDO.setGmtCreate(inDb.getGmtCreate());
		} else {
			// insert
			create(taobaoCatDO);
		}

	}

}
